package com.intelligent.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.intelligent.pojo.ReceiptOrder;
import com.intelligent.service.ReceiptOrderService;
import com.intelligent.utils.Result;
import com.intelligent.vo.ReceiptOrderPageReq;
import com.intelligent.vo.ReceiptOrderResp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/receipt-order")
public class ReceiptOrderController {

    @Autowired
    private ReceiptOrderService service;

    //分页查询收款单
    @PostMapping("/page")
    public Result<Page<ReceiptOrderResp>> page(@RequestBody ReceiptOrderPageReq req) {
        Page<ReceiptOrderResp> page = service.page(req);
        return Result.success(page);
    }

    //查看收款单详情

    @GetMapping("/{id}")
    public Result<ReceiptOrderResp> detail(@PathVariable Integer id) {
        ReceiptOrderResp resp = service.detail(id);
        return resp == null ? Result.error("未找到收款单") : Result.success(resp);
    }


    //新建收款单

    @PostMapping("/create")
    public Result<?> create(@RequestBody ReceiptOrder receiptOrder) {
        boolean ok = service.create(receiptOrder);
        return ok ? Result.success(receiptOrder) : Result.error("保存失败");
    }
}
